package com.solo.system.model.user;

import com.solo.system.api.entity.SysUserRole;
import com.solo.system.model.user.req.AssignRoleReq;
import com.solo.system.model.user.req.AssignUserReq;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 用户角色转换类
 * @author 十一
 * @since 2024/10/17
 * 人生若只如初见，何事秋风悲画扇
 **/
@Mapper
public interface SysUserRoleConvert {

    SysUserRoleConvert INSTANCE = Mappers.getMapper(SysUserRoleConvert.class);
    
    default List<SysUserRole> convert(AssignRoleReq bean) {
        return bean.getRoleIds().stream().map(roleId -> {
            SysUserRole entity = new SysUserRole();
            entity.setUserId(bean.getUserId());
            entity.setRoleId(roleId);
            return entity;
        }).toList();
    }

    default List<SysUserRole> convert(AssignUserReq bean) {
        return bean.getUserIds().stream().map(userId -> {
            SysUserRole entity = new SysUserRole();
            entity.setRoleId(bean.getRoleId());
            entity.setUserId(userId);
            return entity;
        }).toList();
    }

}
